
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:go_router/go_router.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:xim/common/module/qr.dart';
import 'package:xim/common/style/colors.dart';
import 'package:xim/common/util/qr.dart';
import 'package:xim/widget/common/state.dart';
import 'package:xim/widget/common/ui/cell.dart';

/// 二维码页面【用户、会话二维码】
class UserQrPage extends StatelessWidget with BrightnessMode{

  // 二维码数据
  final IQrResult qrData;

  @override
  List<ModelColor> get brightnessColors => [bgBottomColor,bgTopColor,weakTextColor];

  UserQrPage({Key? key, required this.qrData}) : super(key: key);
  ModelColor bgTopColor = ModelColor(darkColor: const Color(0xff878787), lightColor: const Color(0xff78a7d1));
  ModelColor bgBottomColor = ModelColor(darkColor: const Color(0xffc7c7c7), lightColor: const Color(0xff8eadc9));
  ModelColor weakTextColor = ModelColor(darkColor: const Color(0xffdedede), lightColor: const Color(0xffdedede));

  @override
  Widget build(BuildContext context) {
    initModelColor(context);
    return Container(
      height: double.maxFinite,
      width: double.maxFinite,
      decoration: BoxDecoration(
        gradient: LinearGradient(
          begin: Alignment.topRight,
          end: Alignment.bottomLeft,
          colors: [bgTopColor.color, bgBottomColor.color,]
        )
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          SafeArea(
            child: Cell(
              leftItem: InkWell(
                onTap: ()=>context.pop(),
                child: const Icon(Icons.arrow_back_sharp, color: Color(0xfff2f2f2),),
              ),
              padding: const EdgeInsets.symmetric(horizontal: 18),
              rightItem: const SizedBox(),
            ),
          ),
          const SizedBox(height: 180,),
          QrUtility.create(
            qrData.buildQr(),
              size: 0.65.sw,
              gapLess: true,
              qrEyeStyle: const QrEyeStyle(color: Colors.white, eyeShape:QrEyeShape.square),
            qrDataModuleStyle: const QrDataModuleStyle(dataModuleShape: QrDataModuleShape.square, color: Colors.white,),
          ),
          const SizedBox(height: 6,),
          Text("扫描上面的二维码,加我好友", style: TextStyle(fontSize: 13,color: weakTextColor.color),)
        ],
      ),
    );
  }

}
